#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 15;
int m;
int x, y;
bool same[N][N] = {false};
int cnt[5] = {0};
vector<int> v(1, 0);
int ans = 0;
bool Prime(int pos, int n) {
    for (int i = 1; i < pos; i++) {
        if (same[pos][i] && v[i] != n) return false;
    }
    return true;
}
void dfs(int pos) {
    if (pos > 12) {
        ans++;
        return;
    }
    for (int i = 1; i <= 4; i++) {
        if (!cnt[i]) continue;
        if (!Prime(pos, i)) continue;
        cnt[i]--;
        v.push_back(i);
        dfs(pos + 1);
        cnt[i]++;
        v.pop_back();
    }
}
int main() {
    cin >> cnt[1] >> cnt[2] >> cnt[3] >> cnt[4] >> m;
    while (m--) {
        cin >> x >> y;
        same[x][y] = same[y][x] = true;
    }
    dfs(1);
    cout << ans << endl;
    return 0;
}